package org.lecric.wind44.client.model;

import com.google.gwt.user.client.rpc.IsSerializable;

public abstract class ISpot implements Comparable<ISpot>, IsSerializable
{
	private String name;
	private boolean pub;
	private String user;
	private Integer order;
	
	public ISpot() {
	}
	
	public ISpot(String name, boolean pub, String user, Integer order) {
		this.name = name;
		this.pub = pub;
		this.user = user;
		this.order = order;
	}

	public String getName() {
		return name;
	}
	
	public void setName(String name)
	{
		this.name = name;
	}

	public boolean isPub() {
		return pub;
	}

	public void setPub(boolean pub) {
		this.pub = pub;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}
	
	@Override
	public int compareTo(ISpot o) {
		if(getOrder()==null)
			return compareNames(o);
		else if(o==null || o.getOrder()==null)
			return compareNames(o);
		else
		{
			int result = getOrder().compareTo(o.getOrder());
			return result == 0 ? compareNames(o) : result;
		}
	}

	private int compareNames(ISpot o) {
		if(getName()==null)
			return 1;
		else if(o==null || o.getName()==null)
			return -1;
		else
			return getName().compareToIgnoreCase(o.getName());
	}

	public Integer getOrder() {
		return order;
	}

	public void setOrder(Integer order) {
		this.order = order;
	}
}
